<template>
  <el-dialog
    :title="form.id?'编辑':'新增'"
    :visible.sync="dialogVisible"
    :before-close="close"
    width="30%"
  >
    <el-form label-width="120px">
      <el-form-item label="组织名称">
        <ClassifyTreeSelect @input="getBranchId" @getValue="getBranchNode" :value="queryParams.branchId" size="mini" />
      </el-form-item>
      <el-form-item label="党员姓名">
        <el-select filterable v-model="form.partyMemberId" >
          <el-option
            v-for="item in personList"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="脱离党组织原因">
        <el-select v-model="form.partyOrgReasonsDetac" size="mini" placeholder="请选择">
          <el-option
            v-for="(item,index) in reasonList"
            :key="index"
            :label="item"
            :value="index"
          />
        </el-select>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="confirm">确 定</el-button>
      <el-button @click="close">取 消</el-button>
    </span>
  </el-dialog>
</template>
<script>
import { queryPersonList, add, edit } from '@/api/partyMemberManagement/historicalMember'
export default {
  data () {
    return {
      dialogVisible: false,
      form: {},
      reasonList: ['组织关系转出', '失联', '清退', '死亡', '开除党籍'],
      personList: []
    }
  },
  methods: {
    open (row) {
      this.getPersonList()
      this.form = { ...row }
      this.dialogVisible = true
    },
    getPersonList () {
      queryPersonList().then((res) => {
        this.personList = res?.data || []
      })
    },
    getBranchNode (node) {
      this.form.branchId = node?.id || null
      this.form.branchName = node?.fullNamePartyOrg || null
    },
    getBranchId (id) {
      // console.log('id', id)
    },
    confirm () {
      let submitForm = add
      if (this.form.id) {
        submitForm = edit
      }
      submitForm(this.form).then((res) => {
        this.$message.success('保存成功')
        this.$emit('getData')
        this.close()
      })
    },
    close () {
      this.form = {}
      this.dialogVisible = false
    }
  }
}
</script>
